import os
import numpy as np
import time
import glob
import threading

# data = np.load(r"C:\Python Projects\PycharmProjects\未取对数\IQ正常数据\npy文件\train_0_1.npy")
data = np.load(r"./data/syn_ab_data_0_1.npy")

dir = r"D:test\0.000-6.400\test_data_abnormal"
max_file_cnt = 20
cnt = 0
try:
    os.makedirs(dir)
except:
    pass

def job1():
    global cnt
    while True:
        path = "test_data_" + time.strftime("%Y_%m_%d_%H_%M_%S") + ".npy"
        for f in glob.iglob(dir + "\\tested_*.npy"):
            os.remove(f)
        while cnt >= max_file_cnt:
            pass
        np.save(dir + "\\" + path, data)
        print(path)
        time.sleep(1)
        cnt += 1

def job2():
    global cnt
    while True:
        cnt = len(glob.glob(dir + "\\test_data_*.npy"))
        print(cnt)
        time.sleep(1)

t1 = threading.Thread(target=job1)
t2 = threading.Thread(target=job2)
t1.start()
t2.start()
